#coding:utf-8
#
# #建立图或网络
# ##1无向图
# import networkx as nx
# import matplotlib.pyplot as plt
# import random
# # G = nx.Graph() #建立一个空的无向图
# # G.add_node(1) #添加一个节点1
# # G.add_edge(2,3)
# # G.add_edge(1,2)
# # G.add_edge(3,2)
#
# # print G.nodes()
# # print G.edges()
# # print G.number_of_edges()
# # print G.number_of_nodes()
#
# #2有向图及有无转化
# G = nx.DiGraph()
# G.add_node(1)
# # for i in range(20):
# #     G.add_edge(random.random(),random.random())
# G.add_edge(1,3)
#
# G.add_edge(4,6)
#
# G.add_edge(4,7)
#
# G.add_edge(9,10)
#
#
# print G.nodes()
# print G.edges()
# print G.number_of_edges()
# print G.number_of_nodes()
#
# nx.draw(G)
# plt.show()
#
# p = nx.Graph.to_undirected(G)
#
# print p.nodes()
# print p.edges()
# print p.number_of_edges()
# print p.number_of_nodes()
#
#

import networkx as nx                   #导入networkx包
import matplotlib.pyplot as plt     #导入绘图包matplotlib（需要安装，方法见第一篇笔记）
G =nx.random_graphs.barabasi_albert_graph(100,1)   #生成一个BA无标度网络G
nx.draw(G)                          #绘制网络G
plt.savefig("ba.png")           #输出方式1: 将图像存为一个png格式的图片文件
plt.show()                            #输出方式2: 在窗口中显示这幅图像
